<!--container-->
  <div class="container container-gary">
      <!-- member index -->
      <div class="m-ptb wrap clearfix">
          {include file="common@public/_personal_left"}
          <div class="member-right">
              <div class="member-sign clearfix">
                 <b>地址管理</b> 
                 <div class="address-span">
                    <input class="address-s-color add-click fl" type="button" value="添加收货地址" />
                    <div class="add-display fl hide">
                        <input class="address-s-color keep" data-url='' type="button" value="保存" />
                        <input type="button" class='reset' value="重置" /><input class="add-cancel" type="button" value="取消" />
                    </div>
                 </div>
              </div>
              <div class="member-order min-height">
                  <form action="" method="get" onsubmit="return toVaild()">
                  <div class="m-order-enter add-new-style clearfix">
                      <div class="m-order-left">
                          <div class="m-order-item">
                              <div class="m-order-text">收货人：</div>
                              <div class="m-order-write">
                                  <input class="m-input-small" value="{:input('name')}" type="text" placeholder="请输入收货人姓名" name="name" id="name"/>
                              </div>
                          </div>
                          <div class="m-order-item">
                              <div class="m-order-text">手机号：</div>
                              <div class="m-order-write">
                                  <input class="m-input-small" value="{:input('mobiles')}" type="text" placeholder="请输入收货人手机号" name="mobiles" id="mobile"/>
                              </div>
                          </div>
                          <div class="m-order-item">
                              <div class="m-order-text">地址：</div>
                              <div class="m-order-write">
                                  <input class="m-input-small" type="text" value="{:input('address')}"  placeholder="请输入地址" name="address" id="address"/>
                              </div>
                          </div>
                      </div>
                      <div class="m-order-right">
                          <input class="m-btn-color" type="submit" value="搜索" />
                      </div>
                  </div>
                      </form>
                  <div class="address-manage">
                      <div class="member-thead clearfix">
                          <div class="add-people">收货人</div>
                          <div class="add-area">所在地区</div>
                          <div class="add-detail">详细地址</div>
                          <div class="add-code">邮编</div>
                          <div class="add-phone">电话/手机</div>
                          <div class="add-operate">操作</div>
                          <div class="add-setup">设置</div>
                      </div>
                      {foreach name="address" item="vo"}
                      <div class="address-item">
                          <div class="add-i-total add-people">{$vo.consignee}</div>
                          <div class="add-i-total add-area">{$vo.p_name} {$vo.c_name} {$vo.a_name}</div>
                          <div class="add-i-total add-detail">{$vo.p_name} {$vo.c_name} {$vo.a_name}<br />{$vo.address}</div>
                          <div class="add-i-total add-code">{$vo.postcode}</div>
                          <div class="add-i-total add-phone">{if condition="$vo.mobile eq ''"}{$vo.tel}{elseif condition="$vo.tel eq ''"/}{$vo.mobile}{elseif condition="($vo.tel neq '') && ($vo.mobile neq '')" /}{$vo.mobile}{else /}无信息{/if}</div>
                          <div class="add-i-total add-operate"><span style="cursor:pointer" class='address_edit' data-id="{$vo.addr_id}">修改</span><em>|</em><span style="cursor:pointer" data-id="{$vo.addr_id}" class='address_del'>删除</span></div>
                          {if condition="$vo.is_default eq 1"}
                          <div class="add-i-total add-setup"><span class="add-default" data-id='{$vo.addr_id}' >默认地址</span></div>
                          {else/>}
                          <div class="add-i-total add-setup"><span data-id='{$vo.addr_id}' class='set_default'>默认地址</span></div>
                          {/if}
                      </div>
                      {/foreach}
                      <div class="pager address-pager">
                          {$page}
                          {if condition="$all_page gt 1"}                          
                          <em>到第</em><input class="page-input" type="number" max='{$all_page}' min='1' /><i>页</i><input class="page-btn" type="button" value="确认" />
                          {/if}
                      </div>
                      <div class="newly-address hide">
                          
                      </div>

                  </div>
                  

              </div>
              
          </div>
      </div>

  </div>


<!-- check -->
<!-- menu -->
<script src="/public/static/home/js/region.js"></script>
<script type="text/javascript" src="/public/static/home/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="/public/static/home/js/menu.js"></script>
<script src="/public/static/home/js/icheck.js"></script>
<script>
    function toVaild(){
        var name =$('#name').val();
        var mobile=$('#mobile').val();
        var address=$('#address').val();
        if (name.replace(/(^\s*)|(\s*$)/g, "")=='' && mobile.replace(/(^\s*)|(\s*$)/g, "")=='' && address.replace(/(^\s*)|(\s*$)/g, "")=='')
        {
            alert('请输入搜索参数');
            return false;
        }
    }
    $(function(){
      //top select
      $(".top-select").mouseover(function () {
        $(".top-s-text").show();
      })
      $(".top-select").mouseout(function () {
        $(".top-s-text").hide();
      })
      $(".top-s-text div").click(function () {
        var selecttext = $(this).text();
        $(".top-s-head span").text(selecttext);
        $(this).parent(".top-s-text").hide()
      })
      // top code
      var turn = function(target,time,opts){
      target.find('.top-code').hover(function () {
            $(this).find('.top-c-img').stop().animate(opts[0], time, function () {
			$(this).hide().next().show();
			$(this).next().animate(opts[1],time);
	   });
	   },function(){
	        $(this).find('.top-c-text').animate(opts[0], time, function () {
			    $(this).hide().prev().show();
			    $(this).prev().animate(opts[1],time);
		 });
	     });
        }
        var verticalOpts = [{'width':0},{'width':'80px'}];
        turn($('.top-right'), 150, verticalOpts);
        //menu all
        $(".menu-all div").mouseenter(function () {
            $(this).addClass("current");
            $(".submenu").show();
        })
        $(".submenu").mouseenter(function(){
           $(this).show();
           $(".menu-all div").addClass("current")
        })
        $(".submenu").mouseleave(function(){
           $(this).hide();
           $(".menu-all div").removeClass("current")
        })
        //left submenu
        $(".submenu ul li").each(function () {
            var $this = $(this);
            var $children = $this.find('.submenu-pro');
            var $otherChildren = $this.siblings('li').find('.submenu-pro');
            var $childrenList = $children.children('.submenu-total');
            $this.on({
                'mouseenter': function () {
                    $children.css({ 'display': 'block', 'width': 221 * parseInt($childrenList.size()) });
                    $otherChildren.css('display', 'none');
                },
                'mouseleave': function () {
                    $children.css('display', 'none');
                }
            })
        });
         //input
        $(document).ready(function () {
            var callbacks_list = $('.demo-callbacks ul');
            $('.demo-list input,.sign-in-enter input').on('ifCreated ifClicked ifChanged ifChecked ifUnchecked ifDisabled ifEnabled ifDestroyed', function (event) {
                callbacks_list.prepend('<li><span>#' + this.id + '</span> is ' + event.type.replace('if', '').toLowerCase() + '</li>');
            }).iCheck({
                checkboxClass: 'icheckbox_square-blue',
                radioClass: 'iradio_square-blue',
                increaseArea: '20%'
            });
        });

        //member left
        $(".member-l-title").click(function(){
           $(this).parent(".member-l-list").toggleClass("m-current");
           $(this).parent(".member-l-list").find("ul").slideToggle()
        })
        //content height
        $(".member-left").height($(".member-right").height())
        //address
        $(".add-click").click(function(){
          $.ajax({
            url  : "{:url('address/create')}",
            data : {fetch_type:'address_index'},
            async: false,
            dataType : 'json',
            success  : function(data){
              $('.newly-address').html(data);
              $('.keep').attr('data-url',"{:url('address/create')}");
              $(".newly-address,.add-display").show();
            }
          })
           $(this).hide();
        })

        //修改
        $(".address_edit").click(function(){
          var addrId = $(this).data('id');
          $.ajax({
            url  : "{:url('address/edit')}",
            data : {fetch_type:'address_index',addrId:addrId},
            async: false,
            dataType : 'json',
            success  : function(data){
              $('.newly-address').html(data);
              $('.keep').attr('data-url',"{:url('address/edit')}");
              $(".newly-address,.add-display").show();
            }
          })
        })

        $(".add-cancel").click(function(){
           $(".newly-address,.add-display").hide();
           $(".add-click").show();
        })
        $('.reset').click(function(){
          $('input[type=text]').val('');
          $('select').val('');
        })

        //保存
        $('.keep').click(function(){
          var url = $(this).data('url');
          var province = $('select[name=province]').val();
          var city     = $('select[name=city]').val();
          var area     = $('select[name=area]').val();
          var mobile   = $('input[name=mobile]').val();
          var tel      = $('input[name=tel]').val();

          if(province == '' || city == '' || area == '' || (mobile == '' && tel == '')){
            alert('请完善信息');
            return false;
          }

          if(mobile != '' && !(/^1[34578]\d{9}$/.test(mobile))){ 
            alert("手机号码有误，请重填");  
            return false; 
          }

          $.ajax({
            url  : url,
            data : $('#address_change').serialize(),
            async: false,
            type : 'post',
            dataType : 'json',
            success  : function(data){
              if(data.error == 0){
                alert('操作成功');
                location.href = window.location.href;
              }else{
                alert('操作失败');
              }
            }
          }) 

        })

  //默认地址
  $('.set_default').click(function(){
    $('.add-default').removeClass('add-default');
    $(this).addClass('add-default');
    var addr_id = $(this).data('id');
    $.ajax({
            url  : "{:url('address/setDefault')}",
            data : {addrId:addr_id},
            async: false,
            type : 'post',
            dataType : 'json',
            success  : function(data){
              if(data.error == 0){
                alert('设置成功');
              }
              
            }
          }) 
  })

  //跳转
  $('.page-btn').click(function(){
  var num = $('.page-input').val();
  if(parseInt(num) < 1){
    alert('请填写跳转页数');
    return false;
  }
  var url = window.location.href;
  if(url.indexOf('page') == '-1'){
    if(url.indexOf('?') == '-1'){
      var url = url+"?page="+num;
    }else{
      var url = url+"&page="+num;
    }
  }else{
    var reg = /page=.*$/;
    var url = url.replace(reg,'page='+num);
  }

  location.href=url;

})

  //删除
  $('.address_del').click(function(){
    var addr_id = $(this).data('id');
    var theObj = $(this);
    $.ajax({
            url  : "{:url('address/del')}",
            data : {addrId:addr_id},
            async: false,
            type : 'post',
            dataType : 'json',
            success  : function(data){
              if(data.error == 0){
                theObj.parent().parent().remove();
              }
            }
          }) 
  })

})


</script>
</body>
</html>